<%@Page Language="VB" %> 

<html>
<head>
<script language="VB" runat="server">

Sub Page_Load(Src As Object, E As EventArgs)
  myDataGrid.DataSource = GetCacheItems
  myDataGrid.DataBind()
End Sub

Sub Grid_ItemCommand(sender As Object, e As DataGridCommandEventArgs)
  Try   
     Dim myCacheItemNameLabel As Label
     myCacheItemNameLabel = CType(e.Item.FindControl("CacheItemName"), Label) 

     Dim myCacheItemName As String
     myCacheItemName = myCacheItemNameLabel.Text

     Cache.Remove(myCacheItemname)
  Catch myException As Exception
     RemoveMessage.Text = "The item was not found in the cache or there was an error while removing the cached item."
  End Try

  'Typically you will want to reload the page after
  'readding an item. This ensure that we don't
  'remove the item again each time we load the page
  Response.Redirect("cachemanager.aspx")
End Sub

Function GetCacheItems() As HashTable
  Dim objItem as Object
  Dim strName as String

  Dim myCacheHashTable As New HashTable()

  For Each objItem In Cache
    strName = objItem.Key
  
    'Comment the If..Then if you want to see ALL (System, etc.) items the cache
    'We don't want to see ASP.NET cached system items or ASP.NET Worker Processes
    If (Left(strName, 3) = "IW_") Then
       myCacheHashTable.Add(strName, Cache(strName).GetType().ToString())
    End If

  Next

  GetCacheItems = myCacheHashTable
End Function

</script>
</head>

<body>
<form runat="server">
<p><b>The contents of the ASP.NET application cache are:</b></p>
<asp:Label id="RemoveMessage" runat="server" />
<asp:DataGrid id="myDataGrid" 
              runat="server" 
              AutoGenerateColumns="false"
              OnItemCommand="Grid_ItemCommand">
   <Columns>
      <asp:TemplateColumn HeaderText="Remove">
         <ItemTemplate>
            <asp:LinkButton ID="RemoveButton" Text="Remove" CommandName="RemoveFromCache" runat="server" />
         </ItemTemplate>
      </asp:TemplateColumn>

      <asp:TemplateColumn HeaderText="Name (Key)">
         <ItemTemplate>
            <asp:Label id="CacheItemName" runat="server" Text='<%# Container.DataItem.Key %>' />
         </ItemTemplate>
      </asp:TemplateColumn>

      <asp:TemplateColumn HeaderText="Data Type">
         <ItemTemplate>
            <asp:Label id="CacheItemDataType" runat="server" Text='<%# Container.DataItem.Value %>' />
         </ItemTemplate>
      </asp:TemplateColumn>
   </Columns>
</asp:DataGrid>
</form>
</body>
</html>

